<!DOCTYPE html>
<html lang="zh">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<meta name="keywords" content="dromara.org" />
	<meta name="description" content="dromara.org" />
	<!-- 网页标签标题 -->
	<title>dromara(Open source organization)</title>
	<link rel="shortcut icon" href="/website/img/docsite.ico"/>
	<link rel="stylesheet" href="/website/build/documentation.css" />
</head>
<body>
	<div id="root"><div class="documentation-page" data-reactroot=""><header class="header-container header-container-normal"><div class="header-body"><a href="/website/zh-cn/index.html"><img class="logo" src="/website/img/dromara.png"/></a><div class="search search-normal"><span class="icon-search"></span></div><span class="language-switch language-switch-normal">En</span><div class="header-menu"><img class="header-menu-toggle" src="/website/img/system/menu_gray.png"/><ul><li class="menu-item menu-item-normal"><a href="/website/zh-cn/index.html" target="_self">首页</a><div class="sub-menu"><ul></ul></div></li><li class="menu-item menu-item-normal menu-item-normal-active"><a href="#">文档</a><div class="sub-menu"><ul><li><a href="/website/zh-cn/docs/soul/soul.html" target="_self">Soul</a></li><li><a href="/website/zh-cn/docs/hmily/index.html" target="_self">Hmily</a></li></ul></div></li><li class="menu-item menu-item-normal"><a href="/website/zh-cn/blog/index.html" target="_self">博客</a><div class="sub-menu"><ul></ul></div></li><li class="menu-item menu-item-normal"><a href="/website/zh-cn/community/index.html" target="_self">社区</a><div class="sub-menu"><ul></ul></div></li></ul></div></div></header><section class="content-section"><div class="sidemenu" id="menu"><div class="sidemenu-toggle"><img src="https://img.alicdn.com/tfs/TB1E6apXHGYBuNjy0FoXXciBFXa-200-200.png"/></div><ul><li class="menu-item menu-item-level-1"><span>Soul</span><ul><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/zh-cn/docs/soul/soul.html" target="_self">soul介绍</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/zh-cn/docs/soul/team.html" target="_self">团队介绍</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/zh-cn/docs/soul/induction.html" target="_self">soul极简入门</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/zh-cn/docs/soul/db.html" target="_self">数据库设计</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/zh-cn/docs/soul/config.html" target="_self">数据配置流程</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/zh-cn/docs/soul/dataSync.html" target="_self">数据同步原理</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/zh-cn/docs/soul/metaData.html" target="_self">元数据概念介绍</a></li><li style="height:792px;overflow:hidden" class="menu-item menu-item-level-2"><span>用户使用文档<img style="transform:rotate(0deg)" class="menu-toggle" src="/website/img/system/arrow_down.png"/></span><ul><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/setup.html" target="_self">搭建soul网关环境</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/soul-dict.html" target="_self">字典配置</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-handle.html" target="_self">插件配置模板</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/user-http.html" target="_self">http用户</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/user-dubbo.html" target="_self">dubbo用户</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/user-springcloud.html" target="_self">springCloud用户</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/user-sofa.html" target="_self">sofa用户</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/selector.html" target="_self">选择器规则详解</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/user-dataSync.html" target="_self">数据同步策略</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-divide.html" target="_self">divide插件</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-dubbo.html" target="_self">dubbo插件</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-springcloud.html" target="_self">spring cloud插件</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-sofa.html" target="_self">sofa插件</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-rateLimiter.html" target="_self">rateLimiter插件</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-hystrix.html" target="_self">hystrix插件</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-sentinel.html" target="_self">sentinel插件</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-monitor.html" target="_self">monitor插件</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-waf.html" target="_self">waf插件</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-sign.html" target="_self">sign插件</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-rewrite.html" target="_self">rewrite插件</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/plugin-websocket.html" target="_self">websocket支持</a></li></ul></li><li style="height:360px;overflow:hidden" class="menu-item menu-item-level-2"><span>开发者文档<img style="transform:rotate(0deg)" class="menu-toggle" src="/website/img/system/arrow_down.png"/></span><ul><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/dev-filter.html" target="_self">自定义filter</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/dev-plugin.html" target="_self">自定义插件</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/dev-file.html" target="_self">文件上传下载</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/dev-iphost.html" target="_self">自定义解析IP与host</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/dev-result.html" target="_self">自定义返回结果</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/dev-sign.html" target="_self">自定义签名插件算法与验证</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/dev-client.html" target="_self">多语言http客户端接入</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/dev-thread.html" target="_self">线程模型</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/dev-netty.html" target="_self">soul调优</a></li></ul></li><li style="height:144px;overflow:hidden" class="menu-item menu-item-level-2"><span>社区贡献<img style="transform:rotate(0deg)" class="menu-toggle" src="/website/img/system/arrow_down.png"/></span><ul><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/contributor.html" target="_self">贡献者指南</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/committer.html" target="_self">提交者指南</a></li><li class="menu-item menu-item-level-3"><a href="/website/zh-cn/docs/soul/code-conduct.html" target="_self">编码规范</a></li></ul></li></ul></li></ul></div><div class="doc-content markdown-body" id="doc-body"><h2>说明</h2>
<ul>
<li>
<p>此篇文章是dubbo用户使用dubbo插件支持，以及自己的dubbo服务接入soul网关的教程。</p>
</li>
<li>
<p>支持 alibaba dubbo（&lt; 2.7.x） 以及 apache dubbo (&gt;=2.7.x)。</p>
</li>
<li>
<p>接入前，请正确的启动 <code>soul-admin</code> , 以及<a href="setup.md">搭建环境</a> Ok。</p>
</li>
</ul>
<h2>引入网关对dubbo支持的插件</h2>
<ul>
<li>
<p>在网关的 <code>pom.xml</code> 文件中增加如下依赖：</p>
<ul>
<li>alibaba dubbo 用户, dubbo版本换成你的，注册中心的jar包换成你的，一下是参考。</li>
</ul>
</li>
</ul>
<pre><code class="language-xml">
         <span class="hljs-comment">&lt;!--soul alibaba dubbo plugin start--&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.dromara<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>soul-spring-boot-starter-plugin-alibaba-dubbo<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>${last.version}<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
          <span class="hljs-comment">&lt;!-- soul  alibaba dubbo plugin end--&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.alibaba<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>dubbo<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.6.5<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.curator<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>curator-client<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.0.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.curator<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>curator-framework<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.0.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.curator<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>curator-recipes<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.0.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

</code></pre>
<ul>
<li>apache dubbo 用户，dubbo版本换成你的，使用什么注册中心换成你的,以下是参考,使用什么注册中心，就引入啥。</li>
</ul>
<pre><code class="language-xml">
         <span class="hljs-comment">&lt;!--soul apache dubbo plugin start--&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.dromara<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>soul-spring-boot-starter-plugin-apache-dubbo<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>${last.version}<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
         <span class="hljs-comment">&lt;!--soul apache dubbo plugin end--&gt;</span>

         <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.dubbo<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>dubbo<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.7.5<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
          <span class="hljs-comment">&lt;!-- Dubbo Nacos registry dependency start --&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.dubbo<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>dubbo-registry-nacos<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.7.5<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.alibaba.nacos<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>nacos-client<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.1.4<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
         <span class="hljs-comment">&lt;!-- Dubbo Nacos registry dependency  end--&gt;</span>

         <span class="hljs-comment">&lt;!-- Dubbo zookeeper registry dependency start--&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.curator<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>curator-client<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.0.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.curator<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>curator-framework<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.0.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.curator<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>curator-recipes<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.0.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
         <span class="hljs-comment">&lt;!-- Dubbo zookeeper registry dependency end --&gt;</span>
</code></pre>
<ul>
<li>重启网关服务。</li>
</ul>
<h2>dubbo服务接入网关,可以参考 : <a href="https://github.com/Dromara/soul/tree/master/soul-test/soul-test-dubbo">soul-test-dubbo</a></h2>
<ul>
<li>
<p>alibaba dubbo 用户</p>
<ul>
<li>
<p>springboot</p>
<ul>
<li>引入以下依赖</li>
</ul>
</li>
</ul>
</li>
</ul>
<pre><code class="language-xml">       <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.dromara<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>soul-spring-boot-starter-client-alibaba-dubbo<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>${last.version}<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
       <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<ul>
<li>在你的yml文件中新增如下配置 ：</li>
</ul>
<pre><code class="language-yaml">   <span class="hljs-attr">soul:</span>
     <span class="hljs-attr">dubbo:</span>
       <span class="hljs-attr">adminUrl:</span> <span class="hljs-string">http://localhost:9095</span>
       <span class="hljs-attr">contextPath:</span> <span class="hljs-string">/dubbo</span>
       <span class="hljs-attr">appName:</span> <span class="hljs-string">dubbo</span>
      <span class="hljs-comment"># adminUrl: 为你启动的soul-admin 项目的ip + 端口，注意要加 http://</span>
      <span class="hljs-comment"># contextPath: 为你的这个项目在soul网关的路由前缀，这个你应该懂意思把？ 比如/order ，/product 等等，网关会根据你的这个前缀来进行路由.</span>
      <span class="hljs-comment"># appName：你的应用名称，不配置的话，会默认取 dubbo配置中application 中的名称</span>
</code></pre>
<ul>
<li>
<p>spring</p>
<ul>
<li>引入以下依赖 ：</li>
</ul>
</li>
</ul>
<pre><code class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.dromara<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>soul-client-alibaba-dubbo<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>${last.version}<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
       <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<ul>
<li>在你的 bean定义的xml文件中新增如下 ：</li>
</ul>
<pre><code class="language-xml">        <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span> =<span class="hljs-string">"alibabaDubboServiceBeanPostProcessor"</span> <span class="hljs-attr">class</span> =<span class="hljs-string">"org.dromara.soul.client.alibaba.dubbo.AlibabaDubboServiceBeanPostProcessor"</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">constructor-arg</span>  <span class="hljs-attr">ref</span>=<span class="hljs-string">"dubboConfig"</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

        <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"dubboConfig"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.dromara.soul.client.dubbo.common.config.DubboConfig"</span>&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"adminUrl"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"http://localhost:9095"</span>/&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"contextPath"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"/你的contextPath"</span>/&gt;</span>
             <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"appName"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"你的名字"</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
</code></pre>
<ul>
<li>
<p>apache dubbo 用户</p>
<ul>
<li>
<p>springboot</p>
<ul>
<li>引入以下依赖</li>
</ul>
</li>
</ul>
</li>
</ul>
<pre><code class="language-xml">       <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.dromara<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>soul-spring-boot-starter-client-apache-dubbo<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>${last.version}<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
       <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<ul>
<li>在你的yml文件中新增如下配置 ：</li>
</ul>
<pre><code class="language-yaml">    <span class="hljs-attr">soul:</span>
      <span class="hljs-attr">dubbo:</span>
        <span class="hljs-attr">adminUrl:</span> <span class="hljs-string">http://localhost:9095</span>
        <span class="hljs-attr">contextPath:</span> <span class="hljs-string">/dubbo</span>
        <span class="hljs-attr">appName:</span> <span class="hljs-string">dubbo</span>

       <span class="hljs-comment"># adminUrl: 为你启动的soul-admin 项目的ip + 端口，注意要加 http://</span>
       <span class="hljs-comment"># contextPath: 为你的这个项目在soul网关的路由前缀，这个你应该懂意思把？ 比如/order ，/product 等等，网关会根据你的这个前缀来进行路由.</span>
       <span class="hljs-comment"># appName：你的应用名称，不配置的话，会默认取 dubbo配置中application 中的名称</span>
</code></pre>
<ul>
<li>
<p>spring</p>
<ul>
<li>引入以下依赖 ：</li>
</ul>
</li>
</ul>
<pre><code class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.dromara<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>soul-client-apache-dubbo<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>${last.version}<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
       <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<ul>
<li>在你的 bean定义的xml文件中新增如下 ：</li>
</ul>
<pre><code class="language-xml">         <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span> =<span class="hljs-string">"apacheDubboServiceBeanPostProcessor"</span> <span class="hljs-attr">class</span> =<span class="hljs-string">"org.dromara.soul.client.apache.dubbo.ApacheDubboServiceBeanPostProcessor"</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">constructor-arg</span>  <span class="hljs-attr">ref</span>=<span class="hljs-string">"dubboConfig"</span>/&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

         <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"dubboConfig"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.dromara.soul.client.dubbo.common.config.DubboConfig"</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"adminUrl"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"http://localhost:9095"</span>/&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"contextPath"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"/你的contextPath"</span>/&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"appName"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"你的名字"</span>/&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
</code></pre>
<h2>dubbo 插件设置</h2>
<ul>
<li>
<p>首先在 <code>soul-admin</code> 插件管理中，把<code>dubbo</code> 插件设置为开启。</p>
</li>
<li>
<p>其次在 <code>dubbo</code> 插件中配置你的注册地址,或者其他注册中心的地址.</p>
</li>
</ul>
<pre><code class="language-yaml"><span class="hljs-string">{"register":"zookeeper://localhost:2181"}</span>   <span class="hljs-string">or</span> <span class="hljs-string">{"register":"nacos://localhost:8848"}</span>

</code></pre>
<h2>接口注册到网关</h2>
<ul>
<li>
<p>你dubbo服务实现类的，方法上加上 <code>@SoulDubboClient</code> 注解，表示该接口方法注册到网关。</p>
</li>
<li>
<p>启动你的提供者,输出日志 <code>dubbo client register success</code> 大功告成，你的dubbo接口已经发布到 soul网关.如果还有不懂的，可以参考 <code>soul-test-dubbo</code>项目.</p>
</li>
</ul>
<h2>dubbo用户请求以及参数说明</h2>
<ul>
<li>
<p>说白了，就是通过http的方式来请求你的dubbo服务</p>
</li>
<li>
<p>soul网关需要有一个路由前缀，这个路由前缀就是你接入项目进行配置 <code>contextPath</code></p>
</li>
</ul>
<pre><code class="language-yaml"><span class="hljs-comment"># 比如你有一个 order服务 它有一个接口，它的注册路径 /order/test/save</span>

<span class="hljs-comment"># 现在就是通过 post方式请求网关：http://localhost:9195/order/test/save</span>

<span class="hljs-comment"># 其中 localhost:9195 为网关的ip端口，默认端口是9195 ，/order 是你dubbo接入网关配置的 contextPath</span>

</code></pre>
<ul>
<li>
<p>参数传递：</p>
<ul>
<li>
<p>通过 http post 方式访问网关，通过body，json类型传递。</p>
</li>
<li>
<p>更多参数类型传递，可以参考 <a href="https://github.com/Dromara/soul/tree/master/soul-test/soul-test-dubbo">soul-test-dubbo</a> 中的接口定义，以及参数传递方式。</p>
</li>
</ul>
</li>
<li>
<p>单个java bean参数类型 （默认）</p>
</li>
<li>
<p>多参数类型支持 ,在网关的yaml 配置中新增如下配置：</p>
</li>
</ul>
<pre><code class="language-yaml"><span class="hljs-attr">soul :</span>
    <span class="hljs-attr">dubbo :</span>
      <span class="hljs-attr">parameter:</span> <span class="hljs-string">multi</span>
</code></pre>
<ul>
<li>
<p>自定义实现多参数支持:</p>
<ul>
<li>在你搭建的网关项目中，新增一个类 A，实现 <code>org.dromara.soul.web.dubbo.DubboParamResolveService</code>。</li>
</ul>
</li>
</ul>
<pre><code class="language-java">  <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">DubboParamResolveService</span> </span>{

      <span class="hljs-comment">/**
       * Build parameter pair.
       * this is Resolve http body to get dubbo param.
       *
       * <span class="hljs-doctag">@param</span> body           the body
       * <span class="hljs-doctag">@param</span> parameterTypes the parameter types
       * <span class="hljs-doctag">@return</span> the pair
       */</span>
      Pair&lt;String[], Object[]&gt; buildParameter(String body, String parameterTypes);
  }
</code></pre>
<ul>
<li>
<p><code>body</code>为http中body传的json字符串.</p>
</li>
<li>
<p><code>parameterTypes</code>: 匹配到的方法参数类型列表，如果有多个,则使用<code>,</code>分割。</p>
</li>
<li>
<p>Pair中，left为参数类型，right为参数值，这是dubbo泛化调用的标准</p>
</li>
<li>
<p>把你的类注册成Spring的bean，覆盖默认的实现。</p>
</li>
</ul>
<pre><code class="language-java"> <span class="hljs-meta">@Bean</span>
 <span class="hljs-function"><span class="hljs-keyword">public</span> DubboParamResolveService <span class="hljs-title">A</span><span class="hljs-params">()</span> </span>{
         <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> A();
 }
</code></pre>
<h2>大白话讲解如果通过http --&gt; 网关--&gt; dubbo provider</h2>
<ul>
<li>
<p>说白了，就是把http请求，转成dubbo协议，内部使用dubbo泛化来进行调用。</p>
</li>
<li>
<p>首先你要回想下，你的dubbo服务在接入网关的时候，是不是加了个 <code>@SoulDubboClient</code> 注解，里面是不是有个path字段来指定你请求的路径？</p>
</li>
<li>
<p>你是不是还在yml中配置了一个 <code>contextPath</code>?</p>
</li>
<li>
<p>如果您还记得，那我们就开始。</p>
</li>
<li>
<p>假如你有一个这样的方法, contextPath 配置的是 <code>/dubbo</code></p>
</li>
</ul>
<pre><code class="language-java">    <span class="hljs-meta">@Override</span>
    <span class="hljs-meta">@SoulDubboClient</span>(path = <span class="hljs-string">"/insert"</span>, desc = <span class="hljs-string">"插入一条数据"</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> DubboTest <span class="hljs-title">insert</span><span class="hljs-params">(<span class="hljs-keyword">final</span> DubboTest dubboTest)</span> </span>{
        <span class="hljs-keyword">return</span> dubboTest;
    }

</code></pre>
<ul>
<li>
<p>那么我们请求的路径为: <a href="http://localhost:9195/dubbo/insert">http://localhost:9195/dubbo/insert</a> ,再说一下，<code>localhost:9195</code>是网关的域名，如果你更改了，这里也要改。</p>
</li>
<li>
<p>那么请求参数呢？ <code>DubboTest</code> 是一个javabean对象，有2个字段，id与name ，那么我们通过body中传递这个对象的json数据就好。</p>
</li>
</ul>
<pre><code>{&quot;id&quot;:&quot;1234&quot;,&quot;name&quot;:&quot;XIAO5y&quot;}

</code></pre>
<ul>
<li>如果你的接口中,没有参数，那么body传值为:</li>
</ul>
<pre><code>{}

</code></pre>
<ul>
<li>如果你的接口有很多个参数? 往上看一点，有介绍。</li>
</ul>
</div></section><footer class="footer-container"><div class="footer-body"><img src="/website/img/dromara.png"/><div class="cols-container"><div class="col col-12"><h3>免责声明</h3><p>任何单位或个人转载本网站的所有相关信息，请注明来源。</p></div><div class="col col-6"><dl><dt>文档</dt><dd><a href="/website/zh-cn/docs/soul/soul.html" target="_self">概览</a></dd><dd><a href="/website/zh-cn/docs/soul/soul.html" target="_self">快速开始</a></dd><dd><a href="/website/zh-cn/docs/soul/soul.html" target="_self">开发者指南</a></dd></dl></div><div class="col col-6"><dl><dt>资源</dt><dd><a href="/website/zh-cn/blog/index.html" target="_self">博客</a></dd><dd><a href="/website/zh-cn/community/index.html" target="_self">社区</a></dd></dl></div></div><div class="copyright"><span>Copyright ©2020 xiaoyu@apache.org by xiaoyu</span></div></div></footer></div></div>
	<script src="https://f.alicdn.com/react/15.4.1/react-with-addons.min.js"></script>
	<script src="https://f.alicdn.com/react/15.4.1/react-dom.min.js"></script>
	<script>
		window.rootPath = '/website';
  </script>
	<script src="/website/build/documentation.js"></script>
</body>
</html>